<template>
  <div class="orders-page">
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <div class="ipt">
          <el-input
            placeholder="请输入内容"
            class="input-with-select"
            v-model="query"
            clearable
            @clear="clearFn"
          >
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="getOrderList"
            ></el-button>
          </el-input>
        </div>
      </div>
      <el-table border :data="list">
        <el-table-column type="index" width="50" label="序号">
        </el-table-column>
        <el-table-column
          label="订单编号"
          prop="order_number"
          width="180"
        ></el-table-column>
        <el-table-column label="订单价格" prop="order_price"></el-table-column>
        <el-table-column label="是否付款" prop="pay_status">
          <template #default="{ row }">
            <el-tag v-if="row.pay_status === '0'" type="danger">未付款</el-tag>
            <el-tag v-else type="success">已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send"></el-table-column>
        <el-table-column label="下单时间" prop="update_time" width="170">
          <template #default="{ row }">
            {{ row.update_time | dataFormat }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="180">
          <template #default="{ row }">
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
              @click="isDialogFormShow(row)"
            ></el-button>
            <el-button
              type="success"
              icon="el-icon-location-outline"
              size="mini"
              @click="dialogVisible = true"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          :page-sizes="[5, 10, 15, 20]"
          :page-size="pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @current-change="handleCurrentChange"
          @size-change="changeSize"
        >
        </el-pagination>
      </div>
    </el-card>
    <el-dialog title="修改订单数据" :visible.sync="dialogFormVisible">
      <el-form label-width="120px" :model="formData" :rules="rules" ref="form">
        <el-form-item label="订单价格" prop="order_price">
          <el-input
            type="number"
            style="width: 80%"
            v-model="formData.order_price"
          ></el-input>
        </el-form-item>
        <el-form-item label="是否付款">
          <el-radio-group v-model="formData.pay_status">
            <el-radio label="1">已付款</el-radio>
            <el-radio label="0">未付款</el-radio>
          </el-radio-group>
          <!--          <template #default>-->
          <!--            <el-radio v-model="formData.pay_status" label="1">已付款</el-radio>-->
          <!--            <el-radio v-model="formData.pay_status" label="0">未付款</el-radio>-->
          <!--          </template>-->
        </el-form-item>
        <el-form-item label="是否发货" prop="is_send">
          <template #default>
            <el-radio v-model="formData.is_send" label="是">是</el-radio>
            <el-radio v-model="formData.is_send" label="否">否</el-radio>
          </template>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </div>
    </el-dialog>
    <!--    物流-->
    <el-dialog title="物流进度" :visible.sync="dialogVisible" width="50%">
      <el-timeline>
        <el-timeline-item
          v-for="(activity, index) in progressInfo"
          :key="index"
          :timestamp="activity.time"
        >
          {{ activity.context }}
        </el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>

<script>
import {
  editOrderInfoApi,
  getOrderInfoApi,
  getOrderListApi,
} from "@/api/e-commerce";
import { Message } from "element-ui";

export default {
  name: "OrdersIndex",
  data() {
    return {
      formData: {
        order_price: "",
        is_send: "",
        pay_status: 0,
      },
      dialogVisible: false,
      query: "",
      pagenum: 1,
      pagesize: 10,
      list: [],
      total: 0,
      dialogFormVisible: false,
      radio: 3,
      progressInfo: [
        {
          time: "2020-07-15 12:39:56",
          ftime: "2020-07-15 12:39:56",
          context:
            "已签收,签收人是（快递已送代理点如有问题请联系11053685196）先生/女士，如有疑问请联系派件员寒亭魏飞飞(11053685196、0530-18194261)，如您未收到此快递，请拨打投诉电话：0530--17366376，感谢使用申通快递，期待再次为您服务",
          location: null,
        },
        {
          time: "2020-07-15 08:46:54",
          ftime: "2020-07-15 08:46:54",
          context:
            "山东潍坊寒亭营业厅-寒亭魏飞飞(11053685196,0530-18194261)-派件中",
          location: null,
        },
        {
          time: "2020-07-15 08:38:57",
          ftime: "2020-07-15 08:38:57",
          context: "已到达-山东潍坊寒亭营业厅",
          location: null,
        },
        {
          time: "2020-07-15 06:38:13",
          ftime: "2020-07-15 06:38:13",
          context: "已到达-山东潍坊寒亭营业厅",
          location: null,
        },
        {
          time: "2020-07-14 20:56:45",
          ftime: "2020-07-14 20:56:45",
          context: "山东潍坊转运中心-已发往-山东潍坊寒亭公司",
          location: null,
        },
        {
          time: "2020-07-14 20:52:44",
          ftime: "2020-07-14 20:52:44",
          context: "已到达-山东潍坊转运中心",
          location: null,
        },
        {
          time: "2020-07-14 17:43:48",
          ftime: "2020-07-14 17:43:48",
          context: "已到达-山东潍坊转运中心",
          location: null,
        },
        {
          time: "2020-07-14 10:53:46",
          ftime: "2020-07-14 10:53:46",
          context: "山东临沂转运中心-已发往-山东潍坊转运中心",
          location: null,
        },
        {
          time: "2020-07-14 10:43:31",
          ftime: "2020-07-14 10:43:31",
          context: "已到达-山东临沂转运中心",
          location: null,
        },
        {
          time: "2020-07-14 02:43:20",
          ftime: "2020-07-14 02:43:20",
          context: "安徽合肥转运中心-已发往-山东临沂转运中心",
          location: null,
        },
        {
          time: "2020-07-14 02:41:40",
          ftime: "2020-07-14 02:41:40",
          context: "已到达-安徽合肥转运中心",
          location: null,
        },
        {
          time: "2020-07-13 16:28:13",
          ftime: "2020-07-13 16:28:13",
          context: "安徽阜阳转运中心-已发往-安徽合肥转运中心",
          location: null,
        },
        {
          time: "2020-07-13 15:03:30",
          ftime: "2020-07-13 15:03:30",
          context: "安徽利辛公司-已发往-安徽阜阳转运中心",
          location: null,
        },
        {
          time: "2020-07-13 14:47:56",
          ftime: "2020-07-13 14:47:56",
          context: "安徽利辛公司-已发往-安徽阜阳转运中心",
          location: null,
        },
        {
          time: "2020-07-13 14:37:06",
          ftime: "2020-07-13 14:37:06",
          context: "安徽利辛公司-城南吴彦祖-已收件",
          location: null,
        },
      ],
      rules: {
        order_price: [{ required: true, message: "请输入商品价格" }],
      },
    };
  },
  created() {
    this.getOrderList();
  },
  methods: {
    async submit() {
      this.$refs.form.validate();
      await editOrderInfoApi(this.formData.order_id, this.formData);
      Message.success("修改成功");
      this.dialogFormVisible = false;
      this.getOrderList();
    },
    async isDialogFormShow(row) {
      // console.log(row);
      this.dialogFormVisible = true;
      const res = await getOrderInfoApi(row.order_id);
      // console.log(res);
      this.formData = res.data.data;
      console.log(this.formData);
    },
    async getOrderList() {
      const res = await getOrderListApi({
        query: this.query,
        pagenum: this.pagenum,
        pagesize: this.pagesize,
      });
      // console.log(res);
      this.list = res.data.data.goods;
      this.total = res.data.data.total;
      // console.log(this.list);
      //   下一步 渲染页面
    },
    changeSize(value) {
      // console.log(value);
      this.pagesize = value;
      this.getOrderList();
    },
    handleCurrentChange(value) {
      // console.log(value);
      this.pagenum = value;
      this.getOrderList();
    },
    clearFn() {
      console.log(1);
    },
  },
};
</script>

<style lang="scss" scoped>
.el-breadcrumb {
  margin-bottom: 15px;
}
.el-input {
  width: 33.3%;
}
</style>
